<template>
  <el-cascader size="mini"
               :options="treeData"
               :props="prop"
               separator="-"
               :value="value"
               @change="changeValue" />
</template>

<script>
import { getDepartment } from '@/api/department'
import { transListToTree } from '@/utils'
export default {
  name: 'selectTree',
  data () {
    return {
      treeData: [],
      prop: {
        label: 'name',
        value: 'id'
      }
    }
  },
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  created () {
    this.getDepartment()
  },
  methods: {
    async getDepartment () {
      this.treeData = transListToTree(await getDepartment(), 0)

      // console.log(this.treeData);
    },
    changeValue (list) {
      if (list.length) {
        this.$emit('input', list[list.length - 1])
      } else {
        this.$emit('input', null)
      }

    }
  }
}

</script>

<style>
</style>